/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package printers;

import java.awt.Dialog;
import java.awt.PrintJob;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.print.DocFlavor;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.Attribute;
import javax.swing.JDialog;
import javax.swing.JOptionPane;

/**
 *
 * @author Renato Rosa <2101076@my.ipleiria.pt>
 */
public class Printers {
    private static Printers printers;
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        printers = new Printers();
        //String message = JOptionPane.showInputDialog("Insira um texto a imprimir");
        //printers.showPrintDialog();
        //printers.printMessage();
        printers.showPrinters();
    }

    public Printers() {
    }
    
    private void printMessage() {
        String message = JOptionPane.showInputDialog("Insira um texto a imprimir");
        PrinterJob pj = PrinterJob.getPrinterJob();
        pj.setPrintable(new SimplePrintable(message));
        try {
            pj.print();
        } catch (PrinterException ex) {
            System.err.println(ex.getMessage());
        }
    }
    
    private void showPrinters() {
        //DocFlavor df = DocFlavor.STRING.TEXT_PLAIN;
        //PrintService[] lookupPrintServices = PrintServiceLookup.lookupPrintServices(df, null);
        for (PrintService p : PrintServiceLookup.lookupPrintServices(null, null)) {
            System.out.println("Name: " + p.getName());
            for (Attribute a : p.getAttributes().toArray()) {
                System.out.println("Attribute " + a.getName() + ", Category " + a.getCategory().getSimpleName());
            }
            for (DocFlavor df : p.getSupportedDocFlavors()) {
                System.out.println("DocFlavour mime type " + df.getMimeType() + " media type " + df.getMediaType() + " media subtype " + df.getMediaSubtype());
            }
            for (Class<?> c : p.getSupportedAttributeCategories()) {
                System.out.println("Attribute category " + c.getSimpleName());
            }
            System.out.println("...............................");
        }
    }
    
    private void showPrintDialog() {
        PrinterJob pj = PrinterJob.getPrinterJob();
        pj.printDialog();
    }
    
}
